
package load.logic;

import core.InPort;
import core.DispatcherPort;
import core.StdNode;
import core.TriggerPort;

/**
 * Node which behaves like "while(cond) bodyPort".
 * When 'execute' is triggered, 'bodyPort' is triggered repeatedly, 
 * as long as the value of 'condition' is true.
 * 
 * @author Wijnand
 */
public class While extends StdNode {
	private DispatcherPort bodyPort = new DispatcherPort();
	private DispatcherPort conditionChanged = new DispatcherPort();
	
	private InPort condition = new InPort(Boolean.class);
	
	private TriggerPort execute = new TriggerPort() {
		@Override
		public void callInternal() {
			while (((Boolean)condition.getValue()).booleanValue())
				bodyPort.callTargets();
		}
	};
	
	public While() {
		autoPutPorts();
	}
}
